<?php
namespace app\index\model; 
use think\Model;
use think\Db;
use think\Log;
use PHPExcel;
use PHPExcel_IOFactory;
/**
 * DB operator
 */
class mydb extends Model
{
	// function __construct(argument)
	// {
	// 	# code...
	// }
	public function getpaperlist($page,$limit,$gh)
	{
		$t=Db::query("select paperlist.* from paperlist,user where user.id=paperlist.userid and user.gh=:gh  LIMIT :page,:limit ",['page'=>$page,'limit'=>$limit,'gh'=>$gh]);
		return $t;
	}
	//check if can login and get info or return null
	public function checkLoginInfo($gh,$psd)
	{
		$t=Db::query("select count(*) as cnt from user where gh=:gh and psd=:psd",['gh'=>$gh,'psd'=>$psd]);
		return $t;
	}
	public function changepsd($gh,$psd)
	{
		Db::execute("update user set psd=:psd where gh=:gh",['psd'=>$psd,'gh'=>$gh]);
	}
	public function createANewReport($gh)
	{
		$t=Db::query('select id from user where gh=:gh',['gh'=>$gh]);
		$userid=$t[0]['id'];
		$t=Db::query('select id from paperlist where papercode="" and userid=:userid',['userid'=>$userid]);
		if (count($t)==0) {
			Db::execute('insert into paperlist (papercode,reportaddress,userid) values ("","新生成",:userid)',['userid'=>$userid]);
		}
		$t=Db::query('select id from paperlist where papercode="" and userid=:userid',['userid'=>$userid]);
		// dump($t);
		return $t[0]['id'];
	}
	public function getAllInfobypaperId($paperid)
	{
		$t=Db::query('select * from paperlist where id=:paperid',['paperid'=>$paperid]);
		return $t;
	}
	public function createId($targetscores)
	{
		$cnt=count($targetscores);
		if ($cnt==0) {
			return 1;
		}
		$tid=[];
		foreach ($targetscores as $k => $v) {
			$tid[]=$v['id'];
		}
		for ($i=1; $i <= $cnt; $i++) { 
			if (!in_array($i, $tid)) {
				return $i;
			}
		}
		return $cnt+1;
	}
	public function deletepaperbyid($paperid)
	{
		Db::execute("delete from  paperlist  where id=:paperid",['paperid'=>$paperid]);
	}
	public function getWeightDatabypaperid($paperid)
	{
		$t=Db::query('select targetscores from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$t=json_decode($t[0]['targetscores']); 
		return $t;
		// return json_decode($t[0]['targetscores']);
	}
	public function addnewweightline($paperid)
	{
		$t=Db::query('select targetscores from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$targetscores=$t[0]['targetscores'];
		if (is_null($targetscores)) {
			$targetscores="[]";
		}
		$targetscores=json_decode($targetscores,true);
		$id=$this->createId($targetscores);
		$temp=['id'=>$id,'modulepoint'=>NULL,'tid'=>NULL,"obj1"=>NULL,"obj2"=>NULL,"obj3"=>NULL];
		array_push($targetscores, $temp);
		$newvalue=json_encode($targetscores,true);
		Db::execute("update paperlist set step2='X', targetscores=:targetscores where id=:paperid",['targetscores'=>$newvalue,'paperid'=>$paperid]);
		return $targetscores;
	}
	public function deleteweightlinebypaperidandid($paperid,$id)
	{
		$t=Db::query('select targetscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		$targetscores=$t[0]['targetscores'];
		if (is_null($targetscores)) {
			return;
		}
		$targetscores=json_decode($targetscores,true);
		foreach ($targetscores as $k => $v) {
			if ($v['id']==$id) {
				array_splice($targetscores, $k,1);
			}
		}
		$newvalue=json_encode($targetscores,true);
		Db::execute("update paperlist set step2='X', targetscores=:targetscores where id=:paperid",['targetscores'=>$newvalue,'paperid'=>$paperid]);
	}
	public function updateOneFieldbypaperidandid($paperid,$id,$fieldname,$fieldvalue)
	{
		$t=Db::query('select targetscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		$targetscores=$t[0]['targetscores'];
		if (is_null($targetscores)) {
			return;
		}
		$targetscores=json_decode($targetscores,true);
		foreach ($targetscores as $k => $v) {
			if ($v['id']==$id) {
				$targetscores[$k][$fieldname]=$fieldvalue;
			}
		}
		$newvalue=json_encode($targetscores,true);

		Db::execute("update paperlist set step2='X', targetscores=:targetscores where id=:paperid",['targetscores'=>$newvalue,'paperid'=>$paperid]);

	}

	//现在正在修改
	public function updateStscoreOneFieldbypaperidandid($paperid,$id,$fieldname,$fieldvalue)
	{
		$t=Db::query('select stscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		$stscores=$t[0]['stscores'];
		if (is_null($stscores)) {
			return;
		}
		$targetscores=json_decode($stscores,true);
		foreach ($targetscores as $k => $v) {
			if ($v['顺序']==$id) {
				$targetscores[$k][$fieldname]=$fieldvalue;
			}
		}
		$newvalue=json_encode($targetscores,true);

		Db::execute("update paperlist set step4='X', stscores=:targetscores where id=:paperid",['targetscores'=>$newvalue,'paperid'=>$paperid]);

	}

	public function updateweightlinebypaperidandtid($paperid,$id,$tid,$obj1,$obj2,$obj3)
	{
		$t=Db::query('select targetscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		$targetscores=$t[0]['targetscores'];
		if (is_null($targetscores)) {
			return;
		}
		$targetscores=json_decode($targetscores,true);
		foreach ($targetscores as $k => $v) {
			if ($v['id']==$id) {
				$v['tid']=$tid;
				$v['obj1']=$obj1;
				$v['obj2']=$obj2;
				$v['obj3']=$obj3;
			}
		}
		$newvalue=json_encode($targetscores,true);
		Db::execute("update paperlist set step2='X', targetscores=:targetscores where id=:paperid",['targetscores'=>$newvalue,'paperid'=>$paperid]);
	}



	public function updatedatabypaperid($papaername,$major,$coursename,$examdate,$stclass,$exammodel,$classobject1,$classobject2,$classobject3,$paperid)
	{
		$t=Db::query('select count(*) as cnt from paperlist where papercode=:papaername and id<>:paperid',['papaername'=>$papaername,'paperid'=>$paperid]);
		if ($t[0]['cnt']>0) {
			return 0;
		}
		Db::execute("UPDATE paperlist SET  papercode=:papaername,reportaddress='正在生成',major=:major,stclass=:stclass,target1=:classobject1,target2=:classobject2,target3=:classobject3,coursename=:coursename,examdate=:examdate,exammodel=:exammodel,step1=:step1 WHERE id=:paperid",['papaername'=>$papaername,'major'=>$major,'stclass'=>$stclass,'classobject1'=>$classobject1,'classobject2'=>$classobject2,'classobject3'=>$classobject3,'coursename'=>$coursename,'examdate'=>$examdate,'exammodel'=>$exammodel,'step1'=>'Y','paperid'=>$paperid]);
		return 1;
	}
	public function updateweightsbypaperid($paperid,$pscj,$qmcj,$psobj1,$psobj2,$psobj3)
	{
		$weights=json_encode(['pscj'=>$pscj,'qmcj'=>$qmcj,'psobj1'=>$psobj1,'psobj2'=>$psobj2,'psobj3'=>$psobj3],true);
		Db::execute("UPDATE paperlist SET  weights=:weights,step2=:step2 WHERE id=:paperid",['weights'=>$weights,'step2'=>'Y','paperid'=>$paperid]);
	}
	public function getpscjandqmcj($paperid)
	{
		$t=Db::query('select weights from paperlist where id=:paperid',['paperid'=>$paperid]);
		return $t[0]['weights'];
	}

	public function getStepFlagsandpapername($paperid)
	{
		$t=Db::query('select papercode,step1,step2,step3,step4,step5,step6 from paperlist where id=:paperid',['paperid'=>$paperid]);
		return $t[0];
	}
	public function updatestscoresbypaperid($paperid,$stscores)
	{
		$stscores_json=json_encode($stscores,true);
		Db::execute("UPDATE paperlist SET  stscores=:stscores WHERE id=:paperid",['stscores'=>$stscores_json,'paperid'=>$paperid]);
	}
	public function checkIfFinishedForStscoresInDiv4($paperid)
	{
		$t=Db::query('select targetscores,stscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		$targetM=$t[0]['targetscores'];
		$w=$t[0]['stscores'];
		if (is_null($w)) {
			return ['result'=>0,'info'=>'无学生成绩信息，请检查！'];
		}
		$x=json_decode($w,true);
		$tm=json_decode($targetM,true);
		$TM=[];
		foreach ($tm as $key => $value) {
			$TM['M'.$value['tid']]=$value['modulepoint'];
		}
		foreach ($x as $k => $v) { 
			if ($v['平时']=='') {
				return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩平时成绩没有录入'];
			}
			if (intval($v['平时'])>100) {
				return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩平时成绩大于100了'];
			}
			
			
			if ($v['期末']!=null) { 
				if ((intval($v['期末'])>0)) {
					$tempsum=0;
					foreach ($v as $key => $value) {
						if (strpos($key, 'M')===0) {
							if ($value>$TM[$key]) {
								return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩有'.$key.'模块成绩超卷面成绩，请检查！'];
							}

							if (is_null($value)) {
								return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩有'.$key.'模块成绩未录完成，请检查！'];
							}
							if ($value==='') {
								return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩录入未录完成，请检查'.$key.'值为'.$value.'！'];
							}
							$tempsum=$tempsum+($value);
				 		}
					}
					if ($tempsum!=intval($v['期末'])) {
						return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩总和与期末成绩不符，请检查！'];
					}
				}
			}
			else{
				foreach ($v as $key => $value) {
						if (strpos($key, 'M')===0) {
							if ($value>$TM[$key]) {
								return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩有'.$key.'模块成绩超卷面成绩，请检查！'];
							}
							if (is_null($value)) {
								return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩有'.$key.'模块成绩未录完成，请检查！'];
							}
							if ($value==='') {
								return ['result'=>0,'info'=>'顺序为'.$v['顺序'].'的学生成绩录入未录完成，请检查'.$key.'值为'.$value.'！'];
							} 
				 		}
					}
			}
		}
		Db::execute("UPDATE paperlist SET  step4='Y' WHERE id=:paperid",['paperid'=>$paperid]);
		return ['result'=>1,'info'=>'学生成绩信息录入完成！'];
	}
	public function checkorupdatestscores($paperid,$stcounts)
	{
		$t=Db::query('select stscores from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$w=$t[0]['stscores'];
		$x=json_decode($w,true);
		$t=[];
		if (!is_null($w)) { 
			if ($stcounts==count($x)) {
				$t=$x;
			} else{
				$t=[];
			}
		} 
		if (count($t)==0)
		{
			for ($i=1; $i <= $stcounts; $i++) { 
			array_push($t, ['顺序'=>$i,'学号'=>'','姓名'=>'','平时'=>'','期中'=>'','期末'=>'','实验'=>'','总评'=>'']);
			}
		}
		$M=$this->getModelofModulers($paperid); 
		for ($i=0; $i <count($t) ; $i++) {
			foreach ($t[$i] as $key => $value) {
			 	if (strpos($key, 'M')===0) {
			 		unset($t[$i][$key]);
			 		Log::write($key);
			 	}
			 } 
			foreach ($M as $k => $v) {
				$t[$i]['M'.$v['tid']]='';
			}
		}  
		$this->updatestscoresbypaperid($paperid,$t);
		Db::execute("UPDATE paperlist SET  step3='Y' WHERE id=:paperid",['paperid'=>$paperid]);
	}
	public function getModelofModulers($paperid)
	{
		$t=Db::query('select targetscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		$targetscores=$t[0]['targetscores'];
		if (is_null($targetscores)) {
			return NULL;
		}
		$targetscores=json_decode($targetscores,true);
		return $targetscores;
	}

	public function getstscoresbypaperid($paperid)
	{
		$t=Db::query('select stscores from paperlist where id=:paperid',['paperid'=>$paperid]);
		if (is_null($t[0]['stscores'])) {
			return [];
		}
		$x=json_decode($t[0]['stscores'],true);
		return $x;
	}
	//形成动态的表头 For stscores table
	public function formDynamicStscoreTableHearStr($paperid)
	{
		$M=$this->getModelofModulers($paperid);
		if (is_null($M)) {
			return '[]';
		}
		$t=[];
		Log::write($M);
		foreach ($M as $k => $v) {
			array_push($t, "{field:'M".$v['tid']."',title:'M".$v['tid']."',edit:'text',align:'center',width:60}");
		}
		$T='['.implode(',', $t).']';
		return $T;
	}
	//新的计算方法20200702
	public function getDrawDataObj($paperid)
	{
		$t=Db::query('select stscores from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$stscores=json_decode($t[0]['stscores'],true);
		$detailweights=$this->getAnalysisData($paperid);
		// dump($detailweights);
		$pscjqmcjweight =json_decode($this->getpscjandqmcj($paperid),true);
		// dump($pscjqmcjweight);
		$stobj1=[];
		$stobj2=[];
		$stobj3=[];
		$stobjtotal=[];
		$i=0;
		foreach ($stscores as $key => $stinfo) {
			$i+=1;
			$stinfo['obj1']=0;
			$stinfo['obj2']=0;
			$stinfo['obj3']=0;
			$stinfo['total']=0;
			foreach ($detailweights['mkfs'] as $M => $mv) { 
				foreach ($detailweights['weight'] as $obj => $objweight) { 
					if ($M=='平时') {
						$stinfo[$obj]+=$stinfo[$M]*$objweight[$M]*$pscjqmcjweight['pscj']/10000;
					}
					else{
						$stinfo[$obj]+=$stinfo[$M]*$objweight[$M]*$pscjqmcjweight['qmcj']/10000;
					}
					
				}
			}
			$stinfo['total']=$stinfo['obj1']+$stinfo['obj2']+$stinfo['obj3'];
			$stscores[$key]=$stinfo;
			array_push($stobj1, [$i,$stinfo['obj1']]);
			array_push($stobj2, [$i,$stinfo['obj2']]);
			array_push($stobj3, [$i,$stinfo['obj3']]);
			array_push($stobjtotal, [$i,$stinfo['total']]);
		}
		$obj1['name']='目标1';
		$obj1['data']=$stobj1;
		$obj2['name']='目标2';
		$obj2['data']=$stobj2;
		$obj3['name']='目标3';
		$obj3['data']=$stobj2;
		$objtotal['name']='总目标';
		$objtotal['data']=$stobjtotal;
		$stcnt=count($stscores);
		$xlabel=[];
		for ($i=0; $i <=$stcnt ; $i++) { 
			array_push($xlabel, ''.($i));
		}

		$result=['xlabel'=>$xlabel,'totaldata'=>$objtotal,'obj1data'=>$obj1,'obj2data'=>$obj2,'obj3data'=>$obj3,'stcnt'=>$stcnt];
 

		return $result;
	}
	public function getachieve($paperid)
	{
				$t=Db::query('select stscores from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$stscores=json_decode($t[0]['stscores'],true);
		$detailweights=$this->getAnalysisData($paperid);
		// dump($detailweights);
		$pscjqmcjweight =json_decode($this->getpscjandqmcj($paperid),true);
		// dump($pscjqmcjweight);
		$stobj1=[];
		$stobj2=[];
		$stobj3=[];
		$stobjtotal=[];
		foreach ($stscores as $key => $stinfo) {
			$stinfo['obj1']=0;
			$stinfo['obj2']=0;
			$stinfo['obj3']=0;
			$stinfo['total']=0;
			foreach ($detailweights['mkfs'] as $M => $mv) { 
				foreach ($detailweights['weight'] as $obj => $objweight) { 
					if ($M=='平时') {
						$stinfo[$obj]+=$stinfo[$M]*$objweight[$M]*$pscjqmcjweight['pscj']/10000;
					}
					else{
						$stinfo[$obj]+=$stinfo[$M]*$objweight[$M]*$pscjqmcjweight['qmcj']/10000;
					}
					
				}
			}
			$stinfo['total']=$stinfo['obj1']+$stinfo['obj2']+$stinfo['obj3'];
			$stscores[$key]=$stinfo;
			array_push($stobj1, $stinfo['obj1']);
			array_push($stobj2, $stinfo['obj2']);
			array_push($stobj3, $stinfo['obj3']);
			array_push($stobjtotal, $stinfo['total']);
		}
		// foreach ($stscores as $key => $stinfo) {
		// 	dump($stinfo);
		// }
		// dump($stobj1);
		// dump($stobj2);
		// dump($stobj3);
		// dump($stobjtotal);
		$stcnt=count($stscores);
		$stpre15cnt=ceil($stcnt*0.15);
		$sortedobj1=$stobj1;
		rsort($sortedobj1);
		$t1=array_slice($sortedobj1, 0,$stpre15cnt); 
		$sortedobj2=$stobj2;
		rsort($sortedobj2);
		$t2=array_slice($sortedobj2, 0,$stpre15cnt); 
		$sortedobj3=$stobj3;
		rsort($sortedobj3);
		$t3=array_slice($sortedobj3, 0,$stpre15cnt); 
		$sortedobjtotal=$stobjtotal;
		rsort($sortedobjtotal); 
		$ttotal=array_slice($sortedobjtotal, 0,$stpre15cnt); 
		$avg1=array_sum($t1)/$stpre15cnt;
		$avg1fz=array_sum($stobj1)/$stcnt;
		$avg2=array_sum($t2)/$stpre15cnt;
		$avg2fz=array_sum($stobj2)/$stcnt;
		$avg3=array_sum($t3)/$stpre15cnt;
		$avg3fz=array_sum($stobj3)/$stcnt;
		$avgtotal=array_sum($ttotal)/$stpre15cnt;
		$avgtotalfz=array_sum($stobjtotal)/$stcnt;
		$achieveobj1=$avg1fz/$avg1;
		$achieveobj2=$avg2fz/$avg2;
		$achieveobj3=$avg3fz/$avg3;
		$achieveobjtotal=$avgtotalfz/$avgtotal;
		// dump($achieveobj1);
		// dump($achieveobj2);
		// dump($achieveobj3);
		// dump($achieveobjtotal);
		return ['achieveobj1'=>$achieveobj1,'achieveobj2'=>$achieveobj2,'achieveobj3'=>$achieveobj3,'achieveobjtotal'=>$achieveobjtotal,'stcnt'=>$stcnt,'stobj1'=>$stobj1,'stobj2'=>$stobj2,'stobj3'=>$stobj3,'stobjtotal'=>$stobjtotal];
	}

	//以下获取平均分数据
	public function getDrawDataObj_old($paperid)
	{
		$t=Db::query('select stscores from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$stscores=json_decode($t[0]['stscores'],true); 
		$fm=$this->getFMmatrix($paperid); 
		// dump($fm);
		$xlabel=[];
		foreach ($fm as $fmmk => $fmvalue) {
			array_push($xlabel, $fmmk);
		} 
		// dump($xlabel);
		$objmkavg['obj1']=[];
		$objmkavg['obj2']=[];
		$objmkavg['obj3']=[];
		$obj1numbers['obj1']=[];
		$obj1numbers['obj2']=[];
		$obj1numbers['obj3']=[];
		foreach ($fm as $fmmk => $fmvalue) {
			$objmkavg['obj1'][$fmmk]=0;
			$objmkavg['obj2'][$fmmk]=0;
			$objmkavg['obj3'][$fmmk]=0;
			$objMFSnumbers['obj1'][$fmmk]=[0,0,0,0,0,0,0,0,0,0,0,0,0];
			$objMFSnumbers['obj2'][$fmmk]=[0,0,0,0,0,0,0,0,0,0,0,0,0];
			$objMFSnumbers['obj3'][$fmmk]=[0,0,0,0,0,0,0,0,0,0,0,0,0];
		}  
		// dump($objMFSnumbers);
		foreach ($stscores as $stkey => $stvalue) {  
			foreach ($fm as $fmmk => $fmvalue) { 
				$tobjfz1=intval($stvalue[$fmmk])*$fmvalue['obj1fz']/$fmvalue['jmfz'];
				$tobjfz2=intval($stvalue[$fmmk])*$fmvalue['obj2fz']/$fmvalue['jmfz'];
				$tobjfz3=intval($stvalue[$fmmk])*$fmvalue['obj3fz']/$fmvalue['jmfz'];
				$objmkavg['obj1'][$fmmk]=$objmkavg['obj1'][$fmmk]+$tobjfz1;
				$objmkavg['obj2'][$fmmk]=$objmkavg['obj2'][$fmmk]+$tobjfz2;
				$objmkavg['obj3'][$fmmk]=$objmkavg['obj3'][$fmmk]+$tobjfz3;
				$indexforobj1=$this->getInterval(100*$tobjfz1/$fmvalue['obj1fz']);
				$indexforobj2=$this->getInterval(100*$tobjfz2/$fmvalue['obj2fz']);
				$indexforobj3=$this->getInterval(100*$tobjfz3/$fmvalue['obj3fz']);
				$objMFSnumbers['obj1'][$fmmk][$indexforobj1]=$objMFSnumbers['obj1'][$fmmk][$indexforobj1]+1;
				$objMFSnumbers['obj2'][$fmmk][$indexforobj2]=$objMFSnumbers['obj2'][$fmmk][$indexforobj2]+1;
				$objMFSnumbers['obj3'][$fmmk][$indexforobj3]=$objMFSnumbers['obj3'][$fmmk][$indexforobj3]+1;
			}
			// dump($objmkavg);
		} 
		//转化绝对分数
		$count=count($stscores);
		foreach ($objmkavg as $k => $v) {
			foreach ($v as $kk => $vv) {
				$objmkavg[$k][$kk]=round($objmkavg[$k][$kk]/$count,2);
			}
		}
		// dump($objmkavg);
		//转化为相对分数
		foreach ($objmkavg as $k => $v) {
			foreach ($v as $kk => $vv) {
				$objmkavg[$k][$kk]=round(100*$objmkavg[$k][$kk]/$fm[$kk][$k.'fz'],2);
			}
		}
		// dump($fm);
		// dump($objmkavg);
		$avgdata=[];
		foreach ($objmkavg as $key => $value) {
			$temp=[];
			$temp['name']=str_replace('obj', '目标',  $key);
			$temp['data']=[];
			foreach ($value as $k => $v) {
				array_push($temp['data'], $v);
			}
			array_push($avgdata, $temp);
		}
		//计算分数段个数
		$obj1data=[];
		foreach ($objMFSnumbers['obj1'] as $key => $value) {
			$temp=[];
			$temp['name']=$key;
			$temp['data']=[];
			foreach ($value as $k => $v) {
				array_push($temp['data'], $v);
			}
			array_push($obj1data, $temp);
		}
		$obj2data=[];
		foreach ($objMFSnumbers['obj2'] as $key => $value) {
			$temp=[];
			$temp['name']=$key;
			$temp['data']=[];
			foreach ($value as $k => $v) {
				array_push($temp['data'], $v);
			}
			array_push($obj2data, $temp);
		}
		$obj3data=[];
		foreach ($objMFSnumbers['obj3'] as $key => $value) {
			$temp=[];
			$temp['name']=$key;
			$temp['data']=[];
			foreach ($value as $k => $v) {
				array_push($temp['data'], $v);
			}
			array_push($obj3data, $temp);
		}


		$result=['xlabel'=>$xlabel,'avgdata'=>$avgdata,'obj1data'=>$obj1data,'obj2data'=>$obj2data,'obj3data'=>$obj3data];
 

		return $result;
		// $data=[];
		// $weight_detail=[];
		// foreach ($targetscores as $k => $v) {
		// 	$temp['name']='M'.$v['tid'];
		// 	$temp['data']=[0,0,0,0,0,0,0,0,0,0,0,0];
		// 	$weight_detail['modulepoint']['M'.$v['tid']]=$v['modulepoint']*$weights['qmcj']/100;
		// 	$weight_detail['obj1']['M'.$v['tid']]=$v['obj1']*$weights['qmcj']/100;
		// 	$weight_detail['obj2']['M'.$v['tid']]=$v['obj2']*$weights['qmcj']/100;
		// 	$weight_detail['obj3']['M'.$v['tid']]=$v['obj3']*$weights['qmcj']/100;
		// 	$data[]=$temp;
		// }
		

		// $data_obj1=[];
  //       $temp['name']='M1';
  //       $temp['data']=[49.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4];
  //       $data_obj1[]=$temp;
  //       $temp['name']='M2';
  //       $temp['data']=[83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3];
  //       $data_obj1[]=$temp;
  //       return $data_obj1;
	}

    public function getInterval($x)
    {
        if ($x<40) {
            return 0;
        }
        if ($x>=100) {
            return 12;
        }
        return 1+intval(($x-40)/5);
    }
	public function getFMmatrix($paperid)
	{
		$w=Db::query('select weights from paperlist where id=:paperid',['paperid'=>$paperid]);
		$weights=json_decode($w[0]['weights'],true);
		$t=$this->getWeightResult($paperid);
		$p['期末']['jmfz']=100;
		$p['期末']['obj1fz']=0;
		$p['期末']['obj2fz']=0;
		$p['期末']['obj3fz']=0;
		foreach ($t as $k => $v) {
			if ($v['mk']=='平时'||$v['mk']=='总计') {
				if ($v['mk']=='平时') {
					$p[$v['mk']]['jmfz']=100;
					$p[$v['mk']]['obj1fz']=round(100*($weights['psobj1']/100),2);
					$p[$v['mk']]['obj2fz']=round(100*($weights['psobj2']/100),2);
					$p[$v['mk']]['obj3fz']=round(100*($weights['psobj3']/100),2);
				}
			}else{
				$p[$v['mk']]['jmfz']=round($v['fz']/($weights['qmcj']/100),2);
				$p[$v['mk']]['obj1fz']=round($v['fz']*($v['obj1weight']/100)/($weights['qmcj']/100),2);
				$p[$v['mk']]['obj2fz']=round($v['fz']*($v['obj2weight']/100)/($weights['qmcj']/100),2);
				$p[$v['mk']]['obj3fz']=round($v['fz']*($v['obj3weight']/100)/($weights['qmcj']/100),2);
				$p['期末']['obj1fz']=$p['期末']['obj1fz']+$p[$v['mk']]['obj1fz'];
				$p['期末']['obj2fz']=$p['期末']['obj2fz']+$p[$v['mk']]['obj2fz'];
				$p['期末']['obj3fz']=$p['期末']['obj3fz']+$p[$v['mk']]['obj3fz'];
			}
			
		}
		return $p;
	}


	public function getAnalysisData($paperid)
	{
		$t=Db::query('select targetscores,weights from paperlist where id=:paperid',['paperid'=>$paperid]);
		$targetscores=json_decode($t[0]['targetscores'],true);
		$weights=json_decode($t[0]['weights'],true);
		$weight_detail=[];
		$fs_detail=[];
		$mkfs_detail=[];
		foreach ($targetscores as $k => $v) { 
			$mkfs_detail['M'.$v['tid']]=$v['modulepoint']*$weights['qmcj']/100;
			$weight_detail['obj1']['M'.$v['tid']]=$v['obj1'];
			$fs_detail['obj1']['M'.$v['tid']]=$v['obj1']*$v['modulepoint']*$weights['qmcj']/10000;
			$weight_detail['obj2']['M'.$v['tid']]=$v['obj2'];
			$fs_detail['obj2']['M'.$v['tid']]=$v['obj2']*$v['modulepoint']*$weights['qmcj']/10000;
			$weight_detail['obj3']['M'.$v['tid']]=$v['obj3'];
			$fs_detail['obj3']['M'.$v['tid']]=$v['obj3']*$v['modulepoint']*$weights['qmcj']/10000;
		}
		$mkfs_detail['平时']=$weights['pscj'];
		$weight_detail['obj1']['平时']=$weights['psobj1'];
		$fs_detail['obj1']['平时']=$weights['psobj1']*$weights['pscj']/100;
		$weight_detail['obj2']['平时']=$weights['psobj2'];
		$fs_detail['obj2']['平时']=$weights['psobj2']*$weights['pscj']/100;
		$weight_detail['obj3']['平时']=$weights['psobj3'];
		$fs_detail['obj3']['平时']=$weights['psobj3']*$weights['pscj']/100;
		$obj_sum=[];
		$obj_sum['obj1']=0;
		foreach ($fs_detail['obj1'] as $key => $value) {
			$obj_sum['obj1']=$obj_sum['obj1']+$value;
		}
		$obj_sum['obj2']=0;
		foreach ($fs_detail['obj2'] as $key => $value) {
			$obj_sum['obj2']=$obj_sum['obj2']+$value;
		}
		$obj_sum['obj3']=0;
		foreach ($fs_detail['obj3'] as $key => $value) {
			$obj_sum['obj3']=$obj_sum['obj3']+$value;
		}
		return ['mkfs'=>$mkfs_detail,'weight'=>$weight_detail,'fs'=>$fs_detail,'obj_sum'=>$obj_sum];
	}
	public function getWeightResult($paperid)
	{
		if (is_null($paperid)) {
			return [];
		}
		$t=Db::query('select targetscores,weights from paperlist where id=:paperid',['paperid'=>$paperid]);
		if (is_null($t[0]['targetscores'])||is_null($t[0]['weights'])) {
			return [];
		}
		$targetscores=json_decode($t[0]['targetscores'],true);
		$weights=json_decode($t[0]['weights'],true);
		$ds=[];
		foreach ($targetscores as $k => $v) { 
			$temp=[];
			$temp['mk']='M'.$v['tid'];
			$temp['fz']=$v['modulepoint']*$weights['qmcj']/100;
			$temp['obj1weight']=$v['obj1'];
			$temp['obj1fz']=$v['obj1']*$v['modulepoint']*$weights['qmcj']/10000;
			$temp['obj2weight']=$v['obj2'];
			$temp['obj2fz']=$v['obj2']*$v['modulepoint']*$weights['qmcj']/10000;
			$temp['obj3weight']=$v['obj3'];
			$temp['obj3fz']=$v['obj3']*$v['modulepoint']*$weights['qmcj']/10000;
			$ds[]=$temp;
		}
		$temp=[];
		$temp['mk']='平时';
		$temp['fz']=$weights['pscj'];
		$temp['obj1weight']=$weights['psobj1'];
		$temp['obj1fz']=$weights['psobj1']*$weights['pscj']/100;
		$temp['obj2weight']=$weights['psobj2'];
		$temp['obj2fz']=$weights['psobj2']*$weights['pscj']/100;
		$temp['obj3weight']=$weights['psobj3'];
		$temp['obj3fz']=$weights['psobj3']*$weights['pscj']/100;
		$ds[]=$temp;
		$temp=[];
		$temp['mk']='总计';
		$temp['fz']=0;
		$temp['obj1weight']=0;
		$temp['obj1fz']=0;
		$temp['obj2weight']=0;
		$temp['obj2fz']=0;
		$temp['obj3weight']=0;
		$temp['obj3fz']=0;
		foreach ($ds as $k => $v) {
			$temp['fz']=$temp['fz']+$v['fz'];
			$temp['obj1fz']=$temp['obj1fz']+$v['obj1fz'];
			$temp['obj2fz']=$temp['obj2fz']+$v['obj2fz'];
			$temp['obj3fz']=$temp['obj3fz']+$v['obj3fz'];
		}
		$temp['obj1fz']=round($temp['obj1fz'],2);
		$temp['obj2fz']=round($temp['obj2fz'],2);
		$temp['obj3fz']=round($temp['obj3fz'],2);
		$temp['obj1weight']=$temp['obj1fz'];
		$temp['obj2weight']=$temp['obj2fz'];
		$temp['obj3weight']=$temp['obj3fz'];



		$ds[]=$temp;
		return $ds;
	}
	public function settargetanalysis($paperid,$obj1descibe,$obj2descibe,$obj3descibe,$obj1pro,$obj2pro,$obj3pro,$obj1method,$obj2method,$obj3method)
	{
		$t['obj1pro']=$obj1pro;
		$t['obj2pro']=$obj2pro;
		$t['obj3pro']=$obj3pro;
		$t['obj1descibe']=$obj1descibe;
		$t['obj2descibe']=$obj2descibe;
		$t['obj3descibe']=$obj3descibe;
		$t['obj1method']=$obj1method;
		$t['obj2method']=$obj2method;
		$t['obj3method']=$obj3method;
		$str=json_encode($t);
		Db::execute("UPDATE paperlist SET  achieveanalysises=:achieveanalysises,step5='Y' WHERE id=:paperid",['achieveanalysises'=>$str,'paperid'=>$paperid]);
	}
	public function gettargetanalysis($paperid)
	{
		$t=Db::query('select achieveanalysises from paperlist where id=:paperid',['paperid'=>$paperid]);
		if (is_null($t[0]['achieveanalysises'])) {
			return null;
		}
		return json_decode($t[0]['achieveanalysises'],true);
	}
	public function get3targetdetail($paperid)
	{
		$t=Db::query('select stscores,weights from paperlist where id=:paperid',['paperid'=>$paperid]); 
		$stscores=json_decode($t[0]['stscores'],true);
		$weight=json_decode($t[0]['weights'],true); 
		$fm=$this->getFMmatrix($paperid); 
		unset($fm['期末']); 
	    // dump($fm);
		$stobjscores=[];
		foreach ($stscores as $stkey => $stvalue) { 
			$objmktemp = []; 
			foreach ($fm as $fmmk => $fmvalue) {
				$objmktemp['obj1']=0;
				$objmktemp['obj2']=0;
				$objmktemp['obj3']=0; 
			}  
			foreach ($fm as $fmmk => $fmvalue) {
					$tobjfz1=intval($stvalue[$fmmk])*$fmvalue['obj1fz']/$fmvalue['jmfz'];
					$tobjfz2=intval($stvalue[$fmmk])*$fmvalue['obj2fz']/$fmvalue['jmfz'];
					$tobjfz3=intval($stvalue[$fmmk])*$fmvalue['obj3fz']/$fmvalue['jmfz']; 
				if (strpos($fmmk, 'M')===0){
					$objmktemp['obj1']=$objmktemp['obj1']+$tobjfz1*$weight['qmcj']/100;
					$objmktemp['obj2']=$objmktemp['obj2']+$tobjfz2*$weight['qmcj']/100;
					$objmktemp['obj3']=$objmktemp['obj3']+$tobjfz3*$weight['qmcj']/100;
				}else{
					$objmktemp['obj1']=$objmktemp['obj1']+$tobjfz1*$weight['pscj']/100;
					$objmktemp['obj2']=$objmktemp['obj2']+$tobjfz2*$weight['pscj']/100;
					$objmktemp['obj3']=$objmktemp['obj3']+$tobjfz3*$weight['pscj']/100;
				}
			} 
			$stobjscores[]=$objmktemp;
		} 
		return $stobjscores;
	}
	public function generatexls($paperid)
	{
		$t=Db::query('select * from paperlist,user where paperlist.id=:paperid and paperlist.userid=user.id',['paperid'=>$paperid]);
		$t=$t[0];
		$targetfile=$t['papercode'];
		$major=$t['major'];//B2
		$writedate=date('Y-m-d');//E2
		$writer=$t['teachername'];//H2
		$coursename=$t['coursename'];//B3
		$examdate=$t['examdate'];//E3
		$stclass=$t['stclass'];//H3
		$exammodel=$t['exammodel']==0?'考试':'考查';//B4
		$weights=json_decode($t['weights'],true);
		$cjgc="平时成绩:".$weights['pscj']."%  期末成绩:".$weights['qmcj']."%";//E4
		$target1=$t['target1'];//B5
		$target2=$t['target2'];//B6
		$target3=$t['target3'];//B7
		$s=$this->getWeightResult($paperid);
		$s_keyColumn=array_column($s, 'mk'); 
        array_multisort($s_keyColumn,SORT_ASC,$s);
        $linecounts=count($s);//B9开始共需要 linecounts 行
        $obj=$this->getAnalysisData($paperid);//D、F、H列
        $achieve=$this->getachieve($paperid);
        $stobj1=$achieve['stobj1'];
        $stobj2=$achieve['stobj2'];
        $stobj3=$achieve['stobj3'];
        $stobjtotal=$achieve['stobjtotal'];
        $stcnt=$achieve['stcnt'];
		$obj1_achieve=round(100*$achieve['achieveobj1'],2).'%';
		$obj2_achieve=round(100*$achieve['achieveobj2'],2).'%';
		$obj3_achieve=round(100*$achieve['achieveobj3'],2).'%';
		$total_achieve=round(100*$achieve['achieveobjtotal'],2).'%';
		$analysis_str=$t['achieveanalysises'];
		$analysis=json_decode($analysis_str,true);//共有9行

		$stDetailScores=$this->get3targetdetail($paperid);

		Vendor("phpexcel.PHPExcel");
        Vendor("phpexcel.PHPExcel.PHPExcel_IOFactory");
        $objPHPExcel = PHPExcel_IOFactory::load('public/filemodel/anamodel.xls');
        // $xls=$objPHPExcel->createSheet();
        $xls=$objPHPExcel->setActiveSheetIndex(1);
        foreach ($stobj1 as $k=>$v) {
        	$xls->setCellValue('A'.($k+1), $k+1)
        	    ->setCellValue('B'.($k+1), $stobj1[$k])
        	    ->setCellValue('C'.($k+1), $k+1)
        	    ->setCellValue('D'.($k+1), $stobj2[$k])
        	    ->setCellValue('E'.($k+1), $k+1)
        	    ->setCellValue('F'.($k+1), $stobj3[$k])
        	    ->setCellValue('G'.($k+1), $k+1)
        	    ->setCellValue('H'.($k+1), $stobjtotal[$k]);
        }



        $xls=$objPHPExcel->setActiveSheetIndex(0);
        $xls->setCellValue('B2', $major); 
        $xls->setCellValue('E2', $writedate); 
        $xls->setCellValue('H2', $writer); 
        $xls->setCellValue('B3', $coursename); 
        $xls->setCellValue('E3', $examdate); 
        $xls->setCellValue('H3', $stclass);
        $xls->setCellValue('B4', $exammodel);  
        $xls->setCellValue('E4', $cjgc); 
        $xls->setCellValue('B5', $target1);
        $xls->setCellValue('B6', $target2);
        $xls->setCellValue('B7', $target3); 
        $xls->insertNewRowBefore(9,$linecounts-1);
        foreach ($s as $k=>$v) {
        	$xls->setCellValue('A'.(9+$k), $v['mk'])
        	    ->setCellValue('B'.(9+$k), $v['fz'])
        	    ->setCellValue('C'.(9+$k), $v['obj1weight'])
        	    ->setCellValue('D'.(9+$k), $v['obj1fz'])
        	    ->setCellValue('E'.(9+$k), $v['obj2weight'])
        	    ->setCellValue('F'.(9+$k), $v['obj2fz'])
        	    ->setCellValue('G'.(9+$k), $v['obj3weight'])
        	    ->setCellValue('H'.(9+$k), $v['obj3fz']);
        }
        $currentline=9+$linecounts;//开始填写分目标达成度
        $xls->setCellValue('D'.$currentline, $obj1_achieve);
        $xls->setCellValue('F'.$currentline, $obj2_achieve);
        $xls->setCellValue('H'.$currentline, $obj3_achieve);
        $currentline=$currentline+1;
        $xls->setCellValue('C'.($currentline), $total_achieve);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '达成情况:'.$analysis['obj1descibe']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '存在问题:'.$analysis['obj1pro']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '教学改进措施:'.$analysis['obj1method']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '达成情况:'.$analysis['obj2descibe']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '存在问题:'.$analysis['obj2pro']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '教学改进措施:'.$analysis['obj2method']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '达成情况:'.$analysis['obj3descibe']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '存在问题:'.$analysis['obj3pro']);
        $currentline=$currentline+1;
        $xls->setCellValue('B'.($currentline), '教学改进措施:'.$analysis['obj3method']);


        $currentline=$currentline+3+16;
        $xls->setCellValue('B'.($currentline), $coursename); 
        $xls->setCellValue('E'.($currentline), $examdate); 
        $xls->setCellValue('G'.($currentline), $stclass);

        $detailstartline=$currentline+2;
        $detailcounts=count($stDetailScores);
        $detaillines=ceil($detailcounts/2);
        $xls->insertNewRowBefore($detailstartline,$detaillines-1);
        $i=0;
        while ($i<$detailcounts) {
        	if ($i<$detaillines) {
        		 $xls->setCellValue('A'.($i+$detailstartline), $i+1);
        		 $xls->setCellValue('B'.($i+$detailstartline), $stDetailScores[$i]['obj1']);
        		 $xls->setCellValue('C'.($i+$detailstartline), $stDetailScores[$i]['obj2']);
        		 $xls->setCellValue('D'.($i+$detailstartline), $stDetailScores[$i]['obj3']);
        	}else{
        		 $xls->setCellValue('E'.($i+$detailstartline-$detaillines), $i+1);
        		 $xls->setCellValue('F'.($i+$detailstartline-$detaillines), $stDetailScores[$i]['obj1']);
        		 $xls->setCellValue('G'.($i+$detailstartline-$detaillines), $stDetailScores[$i]['obj2']);
        		 $xls->setCellValue('H'.($i+$detailstartline-$detaillines), $stDetailScores[$i]['obj3']);
        	}
        	$i=$i+1;
        }

    //图表  
    $labels1 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$B$1:$B$'.$stcnt,null,$stcnt),//一班  
    ); 
    $xLabels1 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$A$1:$A$'.$stcnt,null,$stcnt),//取x轴刻度  
    );  
    $datas1 = array(  
        new \PHPExcel_Chart_DataSeriesValues('Number','Sheet2!$B$1:$B$'.$stcnt,null,$stcnt),//取一班数据   
    );  
  
    $series1 = array(  
        new \PHPExcel_Chart_DataSeries(  
            \PHPExcel_Chart_DataSeries::TYPE_LINECHART,  
            \PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  
            range(0, count($xLabels1)),  
            null,  
            $xLabels1,  
            $datas1  
        )  
    ); //图表框架  
  
    $layout1=new \PHPExcel_Chart_Layout();  
    $layout1->setShowVal(true);  
    $areas1 = new \PHPExcel_Chart_PlotArea($layout1,$series1);  
    // $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);  
    $title1 = new \PHPExcel_Chart_Title("目标一分数分布情况");  
    $ytitle1 = new \PHPExcel_Chart_Title("目标一分数");  
    $chart1 = new \PHPExcel_Chart('scatter_chart',$title1,null,$areas1,false,false,null,null);  
    $chart1->setTopLeftPosition("A24")->setBottomRightPosition("I28"); //图表位置  
    $xls->addChart($chart1); 

        //图表  
    $labels2 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$D$1:$D$'.$stcnt,null,$stcnt),//一班  
    ); 
    $xLabels2 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$C$1:$C$'.$stcnt,null,$stcnt),//取x轴刻度  
    );  
    $datas2 = array(  
        new \PHPExcel_Chart_DataSeriesValues('Number','Sheet2!$D$1:$D$'.$stcnt,null,$stcnt),//取一班数据   
    );  
  
    $series2 = array(  
        new \PHPExcel_Chart_DataSeries(  
            \PHPExcel_Chart_DataSeries::TYPE_LINECHART,  
            \PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  
            range(0, count($xLabels2)),  
            null,  
            $xLabels2,  
            $datas2  
        )  
    ); //图表框架  
  
    $layout2=new \PHPExcel_Chart_Layout();  
    $layout2->setShowVal(true);  
    $areas2 = new \PHPExcel_Chart_PlotArea($layout2,$series2);  
    // $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);  
    $title2 = new \PHPExcel_Chart_Title("目标二分数分布情况");  
    $ytitle2 = new \PHPExcel_Chart_Title("目标二分数");  
    $chart2 = new \PHPExcel_Chart('scatter_chart',$title2,null,$areas2,false,false,null,null);  
    $chart2->setTopLeftPosition("A28")->setBottomRightPosition("I32"); //图表位置  
    $xls->addChart($chart2); 
 

        //图表  
    $labels3 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$F$1:$F$'.$stcnt,null,$stcnt),//一班  
    ); 
    $xLabels3 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$E$1:$E$'.$stcnt,null,$stcnt),//取x轴刻度  
    );  
    $datas3 = array(  
        new \PHPExcel_Chart_DataSeriesValues('Number','Sheet2!$F$1:$F$'.$stcnt,null,$stcnt),//取一班数据   
    );  
  
    $series3 = array(  
        new \PHPExcel_Chart_DataSeries(  
            \PHPExcel_Chart_DataSeries::TYPE_LINECHART,  
            \PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  
            range(0, count($xLabels3)),  
            null,  
            $xLabels3,  
            $datas3  
        )  
    ); //图表框架  
  
    $layout3=new \PHPExcel_Chart_Layout();  
    $layout3->setShowVal(true);  
    $areas3 = new \PHPExcel_Chart_PlotArea($layout3,$series3);  
    // $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);  
    $title3 = new \PHPExcel_Chart_Title("目标三分数分布情况");  
    $ytitle3 = new \PHPExcel_Chart_Title("目标三分数");  
    $chart3 = new \PHPExcel_Chart('scatter_chart',$title3,null,$areas3,false,false,null,null);  
    $chart3->setTopLeftPosition("A32")->setBottomRightPosition("I36"); //图表位置  
    $xls->addChart($chart3); 
 

        //图表  
    $labels4 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$H$1:$H$'.$stcnt,null,$stcnt),//一班  
    ); 
    $xLabels4 = array(  
        new \PHPExcel_Chart_DataSeriesValues('String','Sheet2!$G$1:$G$'.$stcnt,null,$stcnt),//取x轴刻度  
    );  
    $datas4 = array(  
        new \PHPExcel_Chart_DataSeriesValues('Number','Sheet2!$H$1:$H$'.$stcnt,null,$stcnt),//取一班数据   
    );  
  
    $series4 = array(  
        new \PHPExcel_Chart_DataSeries(  
            \PHPExcel_Chart_DataSeries::TYPE_LINECHART,  
            \PHPExcel_Chart_DataSeries::GROUPING_STANDARD,  
            range(0, count($xLabels4)),  
            null,  
            $xLabels4,  
            $datas4  
        )  
    ); //图表框架  
  
    $layout4=new \PHPExcel_Chart_Layout();  
    $layout4->setShowVal(true);  
    $areas4 = new \PHPExcel_Chart_PlotArea($layout4,$series4);  
    // $legend = new \PHPExcel_Chart_Legend(\PHPExcel_Chart_Legend::POSITION_RIGHT,$layout,false);  
    $title4 = new \PHPExcel_Chart_Title("总目标分数分布情况");  
    $ytitle4 = new \PHPExcel_Chart_Title("总目标分数");  
    $chart4 = new \PHPExcel_Chart('scatter_chart',$title4,null,$areas4,false,false,null,null);  
    $chart4->setTopLeftPosition("A36")->setBottomRightPosition("I40"); //图表位置  
    $xls->addChart($chart4); 



        $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
        $objWriter->setIncludeCharts(true); //图表必须  
        $objWriter->save('public/targetxls/'.$targetfile.'.xlsx');

        Db::execute("UPDATE paperlist SET  reportaddress='已生成',step6='Y' WHERE id=:paperid",['paperid'=>$paperid]);
        return $targetfile.'.xlsx';
	}

}